package net.xdclass.component.impl;

import lombok.extern.slf4j.Slf4j;
import net.xdclass.component.MailService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * 邮件发送服务实现类
 *
 * @author JiangZhou
 * @date 2023/4/29 14:31
 */
@Slf4j
@Service
public class MailServiceImpl implements MailService {

    @Resource
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.from}")
    private String from;

    @Override
    public void sendMail(String to, String subject, String content) {
        //创建一个邮件消息对象
        SimpleMailMessage message = new SimpleMailMessage();

        //配置发件人
        message.setFrom(from);

        //配置主题
        message.setSubject(subject);

        //收件人
        message.setTo(to);

        //内容
        message.setText(content);

        //发送邮件

        javaMailSender.send(message);

        log.info("邮件发送成功，内容是:{}",message.toString());
    }
}
